package IO练习;

import java.io.*;

public class TestCopy {

   public static void main(String[] args) throws IOException {
      File file = new File("stream.txt");
      File anoFile = new File("streamCopy.txt");
      copyFile(file, anoFile);
   }

   public static void copyFile(File srcFile, File destFile) throws IOException {
      //从源文件中读取数据，再将数据写入到目标文件当中
      if (!destFile.exists()) {
         destFile.createNewFile();//如果文件不存在先报下错
      }
      InputStream is = new FileInputStream(srcFile);

      OutputStream os = new FileOutputStream(destFile);

      byte[] bytes = new byte[1024];

      int len = 0;
      while ((len = is.read(bytes)) != -1) {
         os.write(bytes, 0, len);
      }
      os.close();
      is.close();
   }
}
